/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 05 - 23
 * Time: 21:12
 */
class ListNode2 {
    int val;
    ListNode2 next = null;

    ListNode2(int val) {
        this.val = val;
    }
}
public class Practice2 {
    public ListNode2 mergeTwoLists(ListNode2 list1, ListNode2 list2) {
        ListNode2 nH = null;
        ListNode2 tH = nH;
        while((list1 != null) && (list2 != null)) {
            if(list1.val > list2.val) {
                tH.next = list2;
                tH =tH.next;
                list2 = list2.next;
            }else {
                tH.next = list1;
                tH =tH.next;
                list1 = list1.next;
            }
        }
        if(list1 != null) {
            tH.next = list1;
        }
        if(list2 != null) {
            tH.next = list2;
        }
        return nH.next;
    }
}
